package com.ruoyi.web.controller.businessSettings;


import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.system.domain.StoreSettings;
import com.ruoyi.system.domain.vo.BusinessSettingsVO;
import com.ruoyi.system.service.IStoreSettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营业设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Api(tags="营业设置")
@RestController
@RequestMapping("/system/businessSettings")
public class BusinessSettingsController extends BaseController
{
    @Autowired
    private IStoreSettingsService storeSettingsService;

    /**
     * 查询营业设置列表
     */
    @ApiOperation("查询营业设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();

        // 1. 先查出 List<StoreSettings>
        List<StoreSettings> entityList = storeSettingsService.selectStoreSettingsListByName(storeName);

        // 2. 转换为 List<BusinessSettingsVO>
        List<BusinessSettingsVO> voList = entityList.stream()
                .map(entity -> {
                    BusinessSettingsVO vo = new BusinessSettingsVO();
                    vo.setId(entity.getId());
                    vo.setStoreId(entity.getStoreId());
                    vo.setStoreName(entity.getStoreName());
                    return vo;
                })
                .collect(Collectors.toList());

        return getDataTable(voList);
    }
}
